package com.example.base;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Formatter;

/*
 * 基于TCP协议的Socket通信，实现远程关机
 * 发送方
 */
public class Sender extends Thread {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("localhost", 8888);
            Formatter output = new Formatter(socket.getOutputStream());
            output.format("shutdown");
            output.flush();

            socket.shutdownOutput();
            output.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
